package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    List<User> selectList(UserDto userDto);

    @Insert("insert into user(username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time)" +
            " values(#{username},#{password},#{name},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
   void insert(User user);


    void deleteByIds(List<Integer> ids);

     @Select("select id,username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time from user where id= #{id}")
    User selectById(Integer id);

      void update(User user);

      @Select("select id,username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time from user order by update_time desc")
    List<User> getAllList();

      @Select("select u.id,u.id, u.username, u.password, u.name, u.phone, u.email, u.gender, u.status, u.dept_id, u.role_id, u.image, u.remark, u.create_time, r.update_time, r.id, r.name, " +
              "r.label, r.remark, r.create_time, r.update_time from user u,role r  where u.role_id=r.id and r.label=#{rolelabel} and status=1")
    List<User> getByRole(String roleLabel);

    @Select("select u.id,u.id, u.username, u.password, u.name, u.phone, u.email, u.gender, u.status, u.dept_id, u.role_id, u.image, u.remark, u.create_time from user u,role r  where u.dept_id=r.id and u.dept_id=#{deptId}")
    List<User> getByDept(Integer deptId);

    @Select("select u.*, r.label role_label from user u left join role r on u.role_id = r.id where username = #{username} ")
    User selectByUsername(String username);
}
